Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCORM: S3 cleaning #43

Open
wants to merge 14 commits into
base: hawthorn
Choose a base branch
from
Open

SCORM: S3 cleaning #43

wants to merge 14 commits into from

Conversation

BarryPaneer
Copy link

@BarryPaneer BarryPaneer commented Jan 15, 2024

Task

Related PR

Tested OSFS in devstack

  • Before + After uploading new SCORM package from SCORM Editor :
[Before]
root@60ee9c98d568:/edx/app/edxapp/edx-platform# ls -alh  /edx/app/edx_ansible/edx_ansible/docker/plays/cms/static/djpyfs/block--v1-_edX-.SLV__0001-.2023--10--10-.type_64_scormxblock-.block_64_c8c2f1fe2c9c4fed926b80942aab5a65/fs/NONE.NONE/
total 492K
drwxr-xr-x 3 root root 4.0K Jan 15 12:11 .
drwxr-xr-x 3 root root 4.0K Jan 15 09:31 ..
drwxr-xr-x 7 root root 4.0K Jan 15 12:11 2b1fe852ed9c4f59b1be5b7636be9f32
-rw-r--r-- 1 root root 480K Jan 15 12:11 2b1fe852ed9c4f59b1be5b7636be9f32.zip

[After   "2b1fe852ed9c4f59b1be5b7636be9f32" Removed ]
root@60ee9c98d568:/edx/app/edxapp/edx-platform# ls -alh  /edx/app/edx_ansible/edx_ansible/docker/plays/cms/static/djpyfs/block--v1-_edX-.SLV__0001-.2023--10--10-.type_64_scormxblock-.block_64_c8c2f1fe2c9c4fed926b80942aab5a65/fs/NONE.NONE/
total 412K
drwxr-xr-x  3 root root 4.0K Jan 16 01:42 .
drwxr-xr-x  3 root root 4.0K Jan 15 09:31 ..
drwxr-xr-x 11 root root 4.0K Jan 16 01:42 d05651820aa84a9faa66e6b19d06a63d
-rw-r--r--  1 root root 399K Jan 16 01:42 d05651820aa84a9faa66e6b19d06a63d.zip

  • After We removed this SCORM XBlock from Course Unit Page :
root@60ee9c98d568:/edx/app/edxapp/edx-platform# ls -alh /edx/app/edx_ansible/edx_ansible/docker/plays/cms/static/djpyfs/block--v1-_edX-.SLV__0001-.2023--10--10-.type_64_scormxblock-.block_64_c8c2f1fe2c9c4fed926b80942aab5a65/fs/NONE.NONE/
ls: cannot access '/edx/app/edx_ansible/edx_ansible/docker/plays/cms/static/djpyfs/block--v1-_edX-.SLV__0001-.2023--10--10-.type_64_scormxblock-.block_64_c8c2f1fe2c9c4fed926b80942aab5a65/fs/NONE.NONE/': No such file or directory
root@60ee9c98d568:/edx/app/edxapp/edx-platform#

Tested in AWS S3

  • Upload a new SCORM Pakcage
>>>>>>> Before uploading this New scorm Package, we already old packages on S3 :  

course_id = ''course-v1:griky+123+123'
from django.conf import settings
from xmodule.modulestore.django import modulestore
from opaque_keys.edx.keys import CourseKey
S3_BUCKET_NAME = settings.DJFS.get('bucket')
course_key = CourseKey.from_string(course_id)
_course = modulestore().get_course(course_key)
scs = [_scorm_block for _scorm_block in modulestore().get_items(_course.id, qualifiers={'category': 'scormxblock'})]
_s3_prefix = scs[0].fs.dir_path[1:]
objects_to_delete = scs[0].fs.client.list_objects_v2(Bucket=S3_BUCKET_NAME, Prefix=_s3_prefix)
In [16]: len(objects_to_delete.get('Contents', []))
Out[16]: 137

>>>>>>> After uploading this New scorm Package, old package replaced with new on S3 :
objects_to_delete = scs[0].fs.client.list_objects_v2(Bucket=S3_BUCKET_NAME, Prefix=_s3_prefix)
In [18]: len(objects_to_delete.get('Contents', []))
Out[18]: 188
 
>>>>>>> Upload Old the scorm package again 
objects_to_delete = scs[0].fs.client.list_objects_v2(Bucket=S3_BUCKET_NAME, Prefix=_s3_prefix)
In [21]: len(objects_to_delete.get('Contents', []))
Out[21]: 137

image

  • Query SCORM packages on S3 again after deleting this Courseware
objects_to_delete = scs[0].fs.client.list_objects_v2(Bucket=S3_BUCKET_NAME, Prefix=_s3_prefix)
In [23]: len(objects_to_delete.get('Contents', []))
Out[23]: 0

@@ -283,6 +330,8 @@ def studio_upload_files(self, request, suffix=''):
cover_images = request._request.FILES.getlist('cover_images[]')

if pkg:
self.discard_scorm_package()
Copy link
Author

@BarryPaneer BarryPaneer Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Deleting scorm packages( 👉 AWS S3 or Disk file system ) before uploading a new one

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? I'll remove this to the end of uploading method.

def release_all_external_resources(self):
"""Called when course/chapter/subsection/unit got removed.
"""
self.discard_scorm_package(remove_scorm_pkg_root=True)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • When removing a Chapter or Section ... , we also remove packages from S3 or DFS.

@BarryPaneer
Copy link
Author

@noahzaozao Moved self.discard_scorm_package() to the end of method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant